<?php
$catalogSearchHelper =  $this->helper('catalogsearch');
$searchItem = $catalogSearchHelper->getEscapedQueryText();
$session = Mage::getSingleton('customer/session');
$urlHelper = Mage::helper('core/url');
?>
<header>
    <div class="header-home clearfix">
        <div class="header-home-left"><!-- http://scan-button -->
            <a href="<?php echo $session->isLoggedIn() ? "http://scan-button" : $this->getUrl('customer/account/login',array('referer'=>$urlHelper->getEncodedUrl())); ?>" id="scan-button"><img src="<?php echo $this->getSkinUrl('images/home-scan.png')?>" /></a>
        </div>
        <div class="header-home-center clearfix">
            <form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
                <span class="fa fa-search fa-2x"></span>
                <input type="search" name="<?php echo $this->helper('catalogsearch')->getQueryParamName() ?>" id="search" placeholder="<?php echo $searchItem ? $searchItem : $this->__('请输入搜索内容') ?>" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>"/>
                <div id="search_autocomplete" class="search-autocomplete"></div>
            </form>
        </div>
        <div class="header-home-right">
            <a href="#"><img src="<?php echo $this->getSkinUrl('images/home-header.png')?>" /></a>
        </div>
    </div>
</header>



<script type="text/javascript">
    //<![CDATA[
    var searchForm = new Varien.searchForm('search_mini_form', '<?php echo $this->__("Search") ?>');
    searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');

	function onProductScanned(sku)
	{
	    if(!sku){return};
	    var link = "<?php echo $this->getUrl('checkout/cart/addAjax')?>?sku="+sku;
	    jQuery.get(link,function(data){
	    	console.log(JSON.parse(data).message);
	        if (JSON.parse(data).code == 200) {
	        	if( typeof changeShoppingCartNumber === 'function'){
                    changeShoppingCartNumber(JSON.parse(data).count);
            	} 
	        	layer.open({
	                    shadeClose:false,
	                    content:'已添加到购物车！',
	                    style:"font-size:0.2rem;font-family: 'Microsoft YaHei', Arial, Helvetica, sans-serif;text-align:center;width:70%;",
	                    time:2
	                });
	        }else{
	        	layer.open({
	                content:"抱歉，没有这件商品！",
	                style:"font-size:0.2rem;font-family: 'Microsoft YaHei', Arial, Helvetica, sans-serif;text-align:center;width:70%;",
	                time:2,
	            })
	        }
	        $j('.layermcont').css({'line-height':'1.2rem','padding':'0'});
	    })
	}
    //]]>
</script>
